package org.platform.processor.diagnose.job;

import com.mc.mic.core.log.bus.BusLogPusher;
import com.mc.mic.core.log.frame.LogBo;
import lombok.extern.slf4j.Slf4j;
import org.platform.constant.LogType;
import org.platform.core.JobManager;
import org.platform.mo.bussmo.log.TreeDiagnoseDetailMqBO;
import org.platform.mo.csmo.common.FD_DiagnoseTaskTreeNode;
import org.platform.mo.db.FdDiagnoseTaskTreeNode;
import org.platform.processor.knowledge.TreeProcessor;
import org.platform.tool.util.BeansUtils;
import org.quartz.InterruptableJob;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 推送故障树诊断详情
 *
 * @author FengJie
 * @date 2018/7/31
 */
@Slf4j
@Component
public class PromoteTreeDiagnoseDetailJob implements InterruptableJob {
    public static final String DATA_KEY = "diagnoseId";

    @Autowired
    private TreeProcessor processor;
    @Autowired
    private BusLogPusher mqLog;
    @Autowired
    private JobManager jobManager;

    @Override
    public void interrupt() {

    }

    @Override
    public void execute(JobExecutionContext context) {
        try {
            List<FdDiagnoseTaskTreeNode> diagnoseList = (List<FdDiagnoseTaskTreeNode>) context.getMergedJobDataMap().get(DATA_KEY);
            List<FD_DiagnoseTaskTreeNode> treeNodeList = BeansUtils.copyListProperties(diagnoseList, FD_DiagnoseTaskTreeNode.class);
            mqLog.log(new LogBo<>(LogType.TREE_DETAILS, new TreeDiagnoseDetailMqBO(treeNodeList)));
        } catch (Exception e) {
            log.error("推送故障树诊断详情错误,异常信息: " + e);
        }
    }

    //@PostConstruct
    //void init() {
    //    JobDetailImpl jd = new JobDetailImpl();
    //    jd.setJobClass(PromoteTreeDiagnoseDetailJob.class);
    //    jd.setKey(JobKey.jobKey(ComUtils.getUUID()));
    //    jd.getJobDataMap().put(PromoteTreeDiagnoseDetailJob.DATA_KEY, "FDS_TP20180810003");
    //
    //    SimpleTrigger trigger = TriggerBuilder.newTrigger()
    //            .withSchedule(SimpleScheduleBuilder
    //                    .simpleSchedule()
    //                    .withIntervalInSeconds(2)
    //                    .repeatForever())
    //            .startNow()
    //            .build();
    //
    //    jobManager.register(jd, trigger);
    //}
}
